package it.kion.util.ui.umenumanager2.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;

public class Item extends MenuItem {

	private boolean isMdd = false;
	private boolean isNewMdd = false;
	public boolean isNewMdd() {
		return isNewMdd;
	}

	public void setNewMdd(boolean isNewMdd) {
		this.isNewMdd = isNewMdd;
	}

	private List<String> warnings = new ArrayList<String>();

	Collection<MenuItem> children = null;

	String businessProcessClass = "";
	String ejbClass = "";
	public String getEjbClass() {
		return ejbClass;
	}

	public void setEjbClass(String ejbClass) {
		this.ejbClass = ejbClass;
	}

	String view = "";
	
	// nome della vista senza il percorso assoluto (solo il nome locale del file)
	private String viewRelative = null;
	// nome del BP senza il percorso assoluto (solo il nome locale del file)
	private String businessProcessClassRelative = null;

	public Item(String label, Folder parent) {
		super(label, parent, Type.ITEM);
		children = new ArrayList<MenuItem>();
	}

	public Item(String label) {
		super(label, Type.ITEM);
		children = new ArrayList<MenuItem>();
	}

	public Collection<MenuItem> getChildren() {
		return children;
	}

	public void setChildren(Collection<MenuItem> children) {
		this.children = children;
	}

	public Collection<Item> getChildOfTypeFolder() {
		Collection<Item> res = new ArrayList<Item>();
		for (MenuItem item : children) {
			if (item instanceof Item) {
				res.add((Item) item);
			}
		}
		return res;
	}

	public Collection<Item> getChildOfTypeItem() {
		Collection<Item> res = new ArrayList<Item>();
		for (MenuItem item : children) {
			if (item instanceof Item) {
				res.add((Item) item);
			}
		}
		return res;
	}

	public String getBusinessProcessClass() {
		return businessProcessClass;
	}

	public void setBusinessProcessClass(String businessProcessClass) {
		this.businessProcessClass = businessProcessClass.trim();
	}

	public void setView(String view) {
		this.view = view.trim();
	}

	public String getView() {
		return view;
	}
	
	public void addWarning(String warn){
		warnings.add(warn);
	}

	public List<String> getWarnings(){
		return warnings;
	}
	
	public boolean isMdd() {
		return isMdd;
	}

	
	public void setMdd(boolean isMdd) {
		this.isMdd = isMdd;
	}

	public String getViewRelative(){
		String res = viewRelative ;
		if(res==null){
			StringTokenizer st = new StringTokenizer(getView() ,"/");
			st.nextToken();
			while(st.hasMoreTokens()){
				String token = st.nextToken();
				if(!st.hasMoreTokens()){
					viewRelative = token;
					res = viewRelative;
				}
			}
		}
		return res;
	}
	
	public String getBusinessProcessClassRelative(){
		String res = businessProcessClassRelative ;
		if(res==null){
			StringTokenizer st = new StringTokenizer(getBusinessProcessClass() ,".");
			st.nextToken();
			while(st.hasMoreTokens()){
				String token = st.nextToken();
				if(!st.hasMoreTokens()){
					businessProcessClassRelative = token;
					res = businessProcessClassRelative;
				}
			}
		}
		return res;
	}
}
